
import { getCurrentCity, getCityInfoByName } from "../../utils/mapHelper";

export const localCityAction = () => {
  return (dispatch) => {
    getCurrentCity()
      .then(res => {
        res.name = res.addressComponents.city.replace("市", '');
        const action = {
          type: "initCity",
          value: res
        };
        dispatch(action);
      })
  }
}


// 根据被点击的城市名称 修改 store中的城市信息
export const changeCurrentCityByName = ({ cityName, address }) => {
  return (dispatch) => {
    getCityInfoByName({ cityName, address })
      .then(res => {
        res.name = res.addressComponents.city.replace("市", '');
        const action = {
          type: "initCity",
          value: res
        };
        dispatch(action);
      })
  }
}